/**
 * Copyright 2016 JustWayward Team
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hzf.booklibrary.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;

import com.hzf.booklibrary.R;
import com.hzf.booklibrary.base.BaseActivity;
import com.hzf.booklibrary.component.AppComponent;
import com.hzf.booklibrary.component.DaggerMainComponent;
import com.hzf.booklibrary.ui.contract.MainContract;
import com.hzf.booklibrary.ui.fragment.RecommendFragment;
import com.hzf.booklibrary.ui.presenter.MainActivityPresenter;
import javax.inject.Inject;

import butterknife.OnClick;

/**
 * 我的书单
 * Created by lfh on 2016/9/23.
 */
public class BookListActivity extends BaseActivity implements MainContract.View{
    private static String classifyName;
    private static int classifyId;
    private RecommendFragment fragment;

    @Inject
    MainActivityPresenter mPresenter;
    public static void startActivity(Context context,String name,int id){
        classifyName =name;
        classifyId = id;
        context.startActivity(new Intent(context, BookListActivity.class));
    }
    @Override
    public int getLayoutId() {
        return R.layout.activity_book_list;
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerMainComponent.builder()
                .appComponent(appComponent)
                .build()
                .inject(this);
    }

    @Override
    public void initTitleBar() {
        mBtnLeft.setText("返回");
        mBtnLeft.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.img_back_left),null,null,null);
        tvCenter.setText(classifyName);
        tvCenter.setTextColor(Color.parseColor("#4f2e0d"));
        mBtnRight.setText("主页");
        mBtnRight.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.img_home),null,null,null);
    }
    @OnClick(R.id.btn_left)
    public void onClickLeft(){
        finish();
    }
    @OnClick(R.id.btn_right)
    public void onClickRight(){
        startActivity(new Intent(this,MainActivity.class));
        finish();
    }
    @Override
    public void initDatas() {
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragment = new RecommendFragment();
        fragmentManager.beginTransaction().add(R.id.ll_fragment_container,fragment).commit();

        Bundle bundle = new Bundle();
        bundle.putString("item",classifyName);
        bundle.putInt("id",classifyId);
        fragment.setArguments(bundle);
    }

    @Override
    public void configViews() {
        //Presenter与Activity关联
        hideStatusBar();
        mPresenter.attachView(this);
    }
    @Override
    public void syncBookShelfCompleted() {}

    @Override
    public void showError() {}

    @Override
    public void complete() {

    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) {
            mPresenter.detachView();
        }
    }
}
